//
//  FindFirstViewController.m
//  A段项目
//
//  Created by dlios on 15/7/10.
//  Copyright (c) 2015年 dlios. All rights reserved.
//

#import "FindFirstViewController.h"
#import "BaseHeader.h"
#import "ActiveViewController.h"
#import "PriceViewController.h"


@interface FindFirstViewController ()<UIScrollViewDelegate>

@property (nonatomic, retain) UIButton *active;
@property (nonatomic, retain) UIButton *priceoff;
@property (nonatomic, retain) UIScrollView *scroll;


@end

@implementation FindFirstViewController

- (void)dealloc
{
    [_active release];
    [_priceoff release];
    [_scroll release];
    [super dealloc];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.translucent = NO;
    self.scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeidth - 100)];
    _scroll.contentSize = CGSizeMake(ScreenWidth * 2, 0);
    _scroll.delegate = self;
    _scroll.pagingEnabled = YES;
    [self.view addSubview:_scroll];
    [_scroll release];
    
    ActiveViewController *active = [[ActiveViewController alloc] init];
    active.view.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeidth);
    [self addChildViewController:active];
    [self.scroll addSubview:active.view];
    [active release];
    
    PriceViewController *price = [[PriceViewController alloc] init];
    price.view.frame = CGRectMake(ScreenWidth, 0, ScreenWidth, ScreenHeidth);
    [self addChildViewController:price];
    [self.scroll addSubview:price.view];
    [price release];
    
    
    self.active = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth / 3, 10, 50, 50)];
    [_active setTitleColor:[UIColor colorWithRed:30 /255.0 green:144 / 255.0 blue:1 alpha:1] forState:UIControlStateNormal];
    [_active addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [_active setTitle:@"活动" forState:UIControlStateNormal];
    
    self.priceoff = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth / 5 * 2.5, 10, 50, 50)];
    [_priceoff setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [_priceoff setTitle:@"降价" forState:UIControlStateNormal];
    _priceoff.titleLabel.font = [UIFont systemFontOfSize:12];
    [_priceoff addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    UIView *title = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeidth / 10)];
    [title addSubview:_active];
    [title addSubview:_priceoff];
    [_active release];
    [_priceoff release];
    
    self.navigationItem.titleView = title;
    // Do any additional setup after loading the view.
}

- (void)buttonAction:(id)sender
{
    UIButton *butt = (UIButton *)sender;
    if (butt == self.active) {
        butt.titleLabel.font = [UIFont systemFontOfSize:17];
        [butt setTitleColor:[UIColor colorWithRed:30 /255.0 green:144 / 255.0 blue:1 alpha:1] forState:UIControlStateNormal];
        _priceoff.titleLabel.font = [UIFont systemFontOfSize:12];
        [_priceoff setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        _scroll.contentOffset = CGPointMake(0, 0);
    } else
    {
        butt.titleLabel.font = [UIFont systemFontOfSize:17];
        [butt setTitleColor:[UIColor colorWithRed:30 /255.0 green:144 / 255.0 blue:1 alpha:1] forState:UIControlStateNormal];
        _active.titleLabel.font = [UIFont systemFontOfSize:12];
        [_active setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        _scroll.contentOffset = CGPointMake(ScreenWidth, 0);
    }
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    NSInteger page = scrollView.contentOffset.x / ScreenWidth;
    if (page == 0) {
        [_active setTitleColor:[UIColor colorWithRed:30 /255.0 green:144 / 255.0 blue:1 alpha:1] forState:UIControlStateNormal];
        _active.titleLabel.font = [UIFont systemFontOfSize:17];
        [_priceoff setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        _priceoff.titleLabel.font = [UIFont systemFontOfSize:12];
    } else
    {
        _priceoff.titleLabel.font = [UIFont systemFontOfSize:17];
        [_priceoff setTitleColor:[UIColor colorWithRed:30 /255.0 green:144 / 255.0 blue:1 alpha:1] forState:UIControlStateNormal];
        _active.titleLabel.font = [UIFont systemFontOfSize:12];
        [_active setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    }
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
